package Model.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import Model.Bean.*;

public class SearchTaskDao {
	public ArrayList<TaskBean> getList(){
		ArrayList<TaskBean> al=new ArrayList<TaskBean>();
		Connecttodatabase cb=new Connecttodatabase();
		Connection con=cb.conn();
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select * from task;";
		try {
			ps=con.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()){
				TaskBean td=new TaskBean();
				td.setTask_id(rs.getInt(1));
				td.setTitle(rs.getString(2));
				td.setStartDate(rs.getString(3));
				td.setEndDate(rs.getString(4));
				td.setReward(rs.getFloat(5));
				td.setContent(rs.getString(6));
				al.add(td);
			}
			for (int i=0;i<al.size();i++){
				int id=al.get(i).getTask_id();
				String sql1="select * from skill_q where task_id="+id+"";
				ps=con.prepareStatement(sql1);
				rs=ps.executeQuery();	
				while(rs.next()){
					al.get(i).setCpp(rs.getFloat(2));
					al.get(i).setJava(rs.getFloat(3));
					al.get(i).setCsharp(rs.getFloat(4));
					al.get(i).setOracle(rs.getFloat(5));
					al.get(i).setPython(rs.getFloat(6));
					al.get(i).setPhp(rs.getFloat(7));
					al.get(i).setCommentnum(rs.getInt(8));
					al.get(i).setAveragemark(rs.getFloat(9));
					
				}
				
			}
			rs.close();
			ps.close();
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		return al;
		
	}
//	public static void main(String[] args){
//		SearchTaskBean st=new SearchTaskBean();
//		for(int i=0;i<st.getList().size();i++){
//			System.out.println(st.getList().get(i).getContent());
//		}
//		System.out.println(st.getList().get(1).getAveragemark());
//	}
}
